document.querySelectorAll('.fileitem').forEach(el => {
    el.addEventListener('click', function (event) {
        if (event.target.tagName === 'INPUT') {
            if (event.target.checked) {
                querySelector('.btn-toolbar .choose').style.display = 'inline-flex'
            } else {
                if (document.querySelectorAll('.fileitem input:checked').length <= 0) {
                    querySelector('.btn-toolbar .choose').style.display = 'none'
                    querySelector('input.total').checked = false
                }
            }
            return
        }
        event.preventDefault()
        let elc = event.target
        while (elc.tagName !== 'TD') {
            // 点击链接才会跳转,.fileitem的ariaLabel为true不跳转
            if (elc.tagName === 'A' && !elc.parentNode.parentNode.ariaLabel) {
                assign(elc.parentNode.dataset['url'])
            }
            if (elc.tagName === 'MAIN') return
            elc = elc.parentNode
        }
        let elcp = elc.parentNode
        // false跳转
        // if (!elcp.ariaLabel) {
        //     assign(elc.dataset['url'])
        // }
        let cur_status = elcp.querySelector('input').checked
        if (elc.classList.contains('select')) {
            elcp.querySelector('input').checked = !cur_status
        } else {
            document.querySelectorAll('.fileitem input').forEach(elt => {
                elt.checked = false
            })
            elcp.querySelector('input').checked = true
        }
        if (elcp.querySelector('input').checked) {
            querySelector('.btn-toolbar .choose').style.display = 'inline-flex'
        } else {
            if (document.querySelectorAll('.fileitem input:checked').length <= 0) {
                querySelector('.btn-toolbar .choose').style.display = 'none'
                querySelector('input.total').checked = false
            }
        }
    }, false)
})
querySelector('input.total').addEventListener('click', function (event) {
    document.querySelectorAll('.fileitem input').forEach(elt => {
        elt.checked = event.target.checked
    })
    if (event.target.checked) {
        querySelector('.btn-toolbar .choose').style.display = 'inline-flex'
    } else {
        querySelector('.btn-toolbar .choose').style.display = 'none'
    }
})